<?php 
require_once 'init.php';
require_once 'ckLogin.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
$db = new dbConn();
//提交处理
if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
	$oldPwd   = $_POST['oldPwd'];
	$newPwd   = $_POST['newPwd'];
	$againPwd = $_POST['againPwd'];
	$shortName= $_POST['shortname'];
	$db->sql = "SELECT id FROM `admin` WHERE userName = '".$_SESSION['userName']."' and userpwd = '".sha1($oldPwd)."'";
	$id = $db->doResult2();
	if ($_SESSION['userId'] == $id['id']){
		if($newPwd == $againPwd){
			$db->sql = "UPDATE admin SET userpwd = '".sha1($newPwd)."',updateDate = '".time()."',shortName='".$shortName."' WHERE id = ".$id['id'];
			$db->doExecute();
			$success = 1;
		}else{
			//错误2：新密码不一致
			$error = 2;
		}	
	}else {
		//错误1：旧密码错误
		$error = 1;
	}
}

$db->sql = "SELECT * FROM admin WHERE id = ".$_SESSION['userId'];
$usersInfo = $db->doResult2();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Simpla Admin</title>

<!--                       CSS                       -->

<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css"
	media="screen" />

<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/main.css" type="text/css"
	media="screen" />

<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css"
	media="screen" />

<!-- Colour Schemes
	  
		Default colour scheme is green. Uncomment prefered stylesheet to use it.
		
		<link rel="stylesheet" href="resources/css/blue.css" type="text/css" media="screen" />
		
		<link rel="stylesheet" href="resources/css/red.css" type="text/css" media="screen" />  
	 
		-->

<!-- Internet Explorer Fixes Stylesheet -->

<!--[if lte IE 7]>
			<link rel="stylesheet" href="resources/css/ie.css" type="text/css" media="screen" />
		<![endif]-->

<!--                       Javascripts                       -->

<!-- jQuery -->
<script type="text/javascript"
	src="resources/scripts/jquery-1.3.2.min.js"></script>

<!-- jQuery Configuration -->
<script type="text/javascript"
	src="resources/scripts/simpla.jquery.configuration.js"></script>

<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>

<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>

<!-- jQuery Datepicker Plugin -->
<script type="text/javascript"
	src="resources/scripts/jquery.datePicker.js"></script>
<script type="text/javascript" src="resources/scripts/jquery.date.js"></script>
<!--[if IE]><script type="text/javascript" src="resources/scripts/jquery.bgiframe.js"></script><![endif]-->


<!-- Internet Explorer .png-fix -->

<!--[if IE 6]>
			<script type="text/javascript" src="resources/scripts/DD_belatedPNG_0.0.7a.js"></script>
			<script type="text/javascript">
				DD_belatedPNG.fix('.png_bg, img, li');
			</script>
		<![endif]-->

</head>

<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		
		<div id="main-content">
			<!-- Page Head -->
			<h2>欢迎使用<?php echo APPLICATION;?>管理后台</h2>
			<p id="page-intro">修改帐号</p>

			<div class="clear"></div>
			<!-- End .clear -->

			<div class="content-box">
				<!-- Start Content Box -->

				<div class="content-box-header">

					<h3>修改帐号</h3>

					<div class="clear"></div>

				</div>
				<!-- End .content-box-header -->

				<div class="content-box-content">

				<!-- Start Notifications -->
				<?php if($success==1):?>
				<div class="notification success png_bg">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
						修改帐号成功！！！
					</div>
				</div>
				<?php endif;?>
				<?php if($error==1 || $error==2):?>
				<div class="notification error png_bg">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
					<?php if($error == 1) echo "旧密码错误！";elseif($error==2) echo "新密码不一致！";?>
					</div>
				</div>
				<?php endif;?>
				<!-- End Notifications -->
				
					<div class="tab-content default-tab" id="tab1">

						<form action="#" method="post">

							<fieldset>
								<!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->

								<p>
									<label>旧密码 <span style="color: red;">*</span></label> 
									<input class="text-input small-input" type="password" id="oldPwd" name="oldPwd" /> 
									<br />
								</p>

								<p>
									<label>新密码 <span style="color: red;">*</span></label> 
									<input class="text-input small-input" type="password" id="newPwd" name="newPwd" /> 
									<br />
								</p>
								
								<p>
									<label>重复新密码 <span style="color: red;">*</span></label> 
									<input class="text-input small-input" type="password" id="againPwd" name="againPwd" /> 
									<br />
								</p>
								
								<p>
									<label>昵称</label> 
									<input class="text-input small-input" type="text" id="shortname" name="shortname" value="<?php echo $usersInfo['shortName'];?>"/> 
									<br />
								</p>
								
								<p>
									<input class="button" type="submit" value="修改" />
								</p>

							</fieldset>

							<div class="clear"></div>
							<!-- End .clear -->

						</form>

					</div>
					<!-- End #tab2 -->

				</div>
				<!-- End .content-box-content -->

			</div>
			<!-- End .content-box -->

			<div class="clear"></div>

			<div id="footer">
				<small> <!-- Remove this notice or replace it with whatever you want -->
					&#169; Copyright 2009 Your Company | Powered by <a
					href="http://themeforest.net/item/simpla-admin-flexible-user-friendly-admin-skin/46073">Simpla
						Admin</a> | <a href="#">Top</a>
				</small>
			</div>
			<!-- End #footer -->

		</div>
		<!-- End #main-content -->

	</div>
</body>


<!-- Download From www.exet.tk-->
</html>
